package com.partsoft.dits;

import org.springframework.util.Assert;

public class BaseDataIntegrateBatch implements DataIntegrateBatch {
	
	private DataIntegrateBatch parentBatch;
	
	private DataEdgeDescriptor dataDescriptor;
	
	private DescriptorAccepter<EdgeDescriptor> accepter;
	
	private Object inputParameter;
	
	private boolean processed;
	
	private Object result;
	
	private Throwable e;
	
	public BaseDataIntegrateBatch() {}
	
	public BaseDataIntegrateBatch(DataEdgeDescriptor dataDescriptor, Object inputParameter) {
		setDataDescriptor(dataDescriptor);
		setInputParameter(inputParameter);
	}
	
	public DescriptorAccepter<EdgeDescriptor> getAccepter() {
		return accepter;
	}

	public void setAccepter(DescriptorAccepter<EdgeDescriptor> accepter) {
		this.accepter = accepter;
	}

	public BaseDataIntegrateBatch(DataIntegrateBatch parentBatch, DataEdgeDescriptor dataDescriptor, Object inputParameter) {
		setDataDescriptor(dataDescriptor);
		setInputParameter(inputParameter);
		setParentBatch(parentBatch);
	}

	
	public DataIntegrateBatch getParentBatch() {
		return parentBatch;
	}

	public void setParentBatch(DataIntegrateBatch parentBatch) {
		this.parentBatch = parentBatch;
	}

	public DataEdgeDescriptor getDataDescriptor() {
		return dataDescriptor;
	}

	public void setDataDescriptor(DataEdgeDescriptor dataDescriptor) {
		Assert.notNull(dataDescriptor);
		this.dataDescriptor = dataDescriptor;
	}

	public Object getInputParameter() {
		return inputParameter;
	}

	public void setInputParameter(Object inputParameter) {
		Assert.notNull(inputParameter);
		this.inputParameter = inputParameter;
	}

	public boolean isProcessed() {
		return processed;
	}

	public void setProcessed(boolean processed) {
		this.processed = processed;
	}

	public Object getResult() {
		return result;
	}

	public void setResult(Object result) {
		Assert.isTrue(!isProcessed(), "已经处理不能再设置返回值。");
		this.result = result;
		setProcessed(true);
	}
	
	public boolean hasResult() {
		return getResult() != null;
	}
	
	public Throwable getException() {
		return e;
	}
	
	public void setException(Throwable e) {
		this.e = e;
		setProcessed(true);
	}
	
	public boolean hasException() {
		return getException() != null;
	}
	
	public void reset() {
		result = null;
		e = null;
		processed = false;
	}
	
}
